<!DOCTYPE HTML>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>LingPowerAI</title>
		<script type="text/javascript">
			document.write('<script src="../../js/fix.js?rd=?rd=' + Math.random() + '"><\/script>');
		</script>
		<script type="text/javascript">
		link(['../../css/reset.css','../../fonts/iconfont/iconfont.css']);
	</script>
		<script type="text/javascript">
		//必须顺序加载
		script();
	</script>
		<style type="text/css">
			.loginformwarp form span {
				color: darkgray;
			}
			.bg-lan-default,
			.bg-lan-default .mui-content {
				background: #47BAFE;
				background-color: #47BAFE;
			}
		input[type="text"],input[type="password"]{
			font-size: 0.15rem;
		}
		</style>
		
	</head>

	<body class="bg-lan-default" style="display: none;">
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">注册</h1>
		</header>
		<div class="mui-content mui-scroll-wrapper scroll">
			<div class="mui-scroll">
				<div class="loginformwarp">
					<div class="m1rem">
						<form class="mui-input-group">
							<div class="input-group">
								<div class="mui-input-row">
									<span class="mui-icon fa fa-tablet"></span>
									<input id='inpt_mobile' type="text" class="mui-input-clear mui-input" placeholder="请输入手机号" value="">
								</div>
								<div class="mui-input-row clearr100">
									<span class="mui-icon fa fa-shield"></span>
									<input id='inpt_validcode' type="text" class="mui-input-clear mui-input" placeholder="请输入手机验证码" value="">
									<button id="btn_sendvalidcode" class="btn-rightwarp">获取验证码</button>
								</div>
								<div class="mui-input-row">
									<span class="mui-icon fa fa-lock"></span>
									<input id='inpt_password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码" value="">
								</div>
								<div class="mui-input-row">
									<span class="mui-icon fa fa-address-book-o" style="font-size: 0.16rem;"></span>
									<input id='inpt_name' type="text" class="mui-input-clear mui-input" style="padding-left: 0.13rem;" placeholder="请输入你的姓名" value="">
								</div>
								<div class="mui-input-row">
									<span class="iconfont iconyaoqingma" style="font-size: 0.15rem;font-weight: bold;"></span>
									<input id='inpt_code' type="text" class="mui-input-clear mui-input" style="padding-left: 0.13rem;" placeholder="邀请码 (选填)" value="">
								</div>
							</div>
						</form>
						<div>
							<button id='btn_ok' class="mui-btn mui-btn-block btn-ok">注册账号</button>
							<div class="linkArea">
								<a id='btn_login' class="mui-pull-right">已有账号?马上登录</a>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function() {
				storage.init();
			 	storageUser = kidstorageuser.getInstance();
				var btn_sendvalidcode = document.getElementById("btn_sendvalidcode");
				var btn_ok = document.getElementById("btn_ok");
				var btn_login = document.getElementById("btn_login");
				var inpt_mobile = document.getElementById("inpt_mobile");
				var inpt_validcode = document.getElementById("inpt_validcode");
				var inpt_password = document.getElementById("inpt_password");
				var inpt_name = document.getElementById("inpt_name");
			    var inpt_code=document.getElementById("inpt_code");
				if(ismobileno(inpt_mobile.value)) {
					appUI.removeDisabled(btn_sendvalidcode);
				}
			
				//发送验证码
				btn_sendvalidcode.addEventListener("tap", function() {
					if(inpt_mobile.value.trim() == "") {
						appUI.showTopTip("请输入手机号");
						//mui.toast("请输入手机号");
						
					} else if(!ismobileno(inpt_mobile.value)) {
						appUI.showTopTip("手机号格式不正确");
						//mui.toast("手机号格式不正确");
					} else {
						appUI.setDisabled(btn_sendvalidcode);
						request("/cmdb/send_sms/", {
							tel_no: inpt_mobile.value,
							type: 'SMS1001'
						}, function(json) {
							inpt_validcode.setAttribute("vcode",json.DATASET[0].sms_code)
							inpt_validcode.setAttribute("vphone",json.DATASET[0].phone)
							mui.toast(json.ERROR_MESSAGE);
							appUI.removeDisabled(btn_sendvalidcode);
							if(json[SysConstants.ERROR_CODE_KEY] == SysConstants.ERROR_CODE_OBJECT.ERROR_CODE_SUCCESS) {
								time(btn_sendvalidcode);
							}
						});
					}
				});
			
				//注册账号
				btn_ok.addEventListener("tap", function() {
					if(inpt_mobile.value.trim() == "") {
						appUI.showTopTip("请输入手机号");
						//mui.toast("请输入手机号");
						//inpt_mobile.focus();
					} else if(!ismobileno(inpt_mobile.value)) {
						appUI.showTopTip("手机号格式不正确");
						//mui.toast("手机号格式不正确");
					} else if(inpt_validcode.value.trim() == "") {
						appUI.showTopTip("请输入验证码");
						//mui.toast("请输入验证码");
						//inpt_pwd.focus();
					} else if(inpt_password.value.trim() == "") {
					 	appUI.showTopTip("请输入密码");
					 	//mui.toast("请输入验证码");
					 	//inpt_pwd.focus();
					 }else if(inpt_name.value.trim() == "") {
					  	appUI.showTopTip("请输入姓名");
					  	//mui.toast("请输入验证码");
					  	//inpt_pwd.focus();
					  }else if(inpt_validcode.value!=inpt_validcode.getAttribute("vcode") || inpt_mobile.value!=inpt_validcode.getAttribute("vphone")) {
					  	appUI.showTopTip("验证码错误");
					  	//mui.toast("请输入验证码");
					  	//inpt_pwd.focus();
					  }else {
						appUI.setDisabled(btn_ok);
						// request("/Login/checkMobileSmsCode", {
						// 	mobile: inpt_mobile.value,
						// 	verifycode: inpt_validcode.value
						request("/cmdb/saveOrUpdate_LpMgntSalesMst/", {
							sales_id:"",
							login_id: inpt_mobile.value,
							tel_no:inpt_mobile.value,
							// validcode: inpt_validcode.value,
							login_pwd: inpt_password.value,
							user_nm: inpt_name.value,
							inpt_code:inpt_code.value
							// user_sn : "20000"
						}, function(json) {
							appUI.removeDisabled(btn_ok);
							if(json[SysConstants.ERROR_CODE_KEY] == SysConstants.ERROR_CODE_OBJECT.ERROR_CODE_SUCCESS) {
								mui.toast("注册成功");
								openNew("login.html", {
									mobile: inpt_mobile.value,
									type: "reg"
								});
							} else {
								appUI.showTopTip(json[SysConstants.ERROR_MESSAGE_KEY]);
								//mui.toast(json.msg);
							}
						});
					}
				});
				
				btn_login.addEventListener("tap", function() {
							let login=plus.webview.create("login.html","login.html")
					setTimeout(function(){
						plus.webview.show(login,"fade-in",100)
					},200);
				});
			});
		</script>
	</body>
</html>